# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Naveen M K <naveen521kk@gmail.com>

_realname=inkscape
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1
pkgrel=6
pkgdesc="Vector graphics editor using the SVG file format (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://inkscape.sourceforge.io/"
license=("GPL" "LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gtest"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "intltool")
depends=("${MINGW_PACKAGE_PREFIX}-aspell"
         "${MINGW_PACKAGE_PREFIX}-double-conversion"
         "${MINGW_PACKAGE_PREFIX}-gc"
         "${MINGW_PACKAGE_PREFIX}-gdl"
         "${MINGW_PACKAGE_PREFIX}-ghostscript"
         "${MINGW_PACKAGE_PREFIX}-graphicsmagick"
         "${MINGW_PACKAGE_PREFIX}-gsl"
         "${MINGW_PACKAGE_PREFIX}-gtkmm3"
         "${MINGW_PACKAGE_PREFIX}-gtkspell3"
         "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache"
         "${MINGW_PACKAGE_PREFIX}-imagemagick"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libcdr"
         "${MINGW_PACKAGE_PREFIX}-librevenge"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libvisio"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libxslt"
         "${MINGW_PACKAGE_PREFIX}-libwpg"
         "${MINGW_PACKAGE_PREFIX}-poppler"
         "${MINGW_PACKAGE_PREFIX}-popt"
         "${MINGW_PACKAGE_PREFIX}-potrace"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-scour")
optdepends=(#"${MINGW_PACKAGE_PREFIX}-pstoedit: latex formulas"
            "${MINGW_PACKAGE_PREFIX}-texlive-scheme-medium: latex formulas"
            "${MINGW_PACKAGE_PREFIX}-python-numpy: some extensions"
            "${MINGW_PACKAGE_PREFIX}-python-lxml: some extensions and filters"
            #"${MINGW_PACKAGE_PREFIX}-scour: optimized SVG output"
            #"${MINGW_PACKAGE_PREFIX}-uniconvertor: reading/writing to some proprietary formats"
            )
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.xz::https://media.inkscape.org/dl/resources/file/${_realname}-${pkgver}.tar.xz"
        inkscape-1.0.1-unbundle.patch
        inkscape-1.0.1-install-layout.patch)
sha256sums=('71e6e8ce3fdf702f59dbc4a276665eb982eb7822b029bbdbeced2df4301795e6'
            '92387251c1740f1a57cde9e587cc673ef1600813617bd2c9db65598c324a24d4'
            '131b2e1190637df0554ef1ee8cf46440689584375c117d057ab47d5871c58128')

prepare() {
  mv "${srcdir}/inkscape-1.1_2021-05-24_c4e8f9ed74" "${srcdir}/${_realname}-${pkgver}"
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/inkscape-1.0.1-unbundle.patch
  patch -p1 -i ${srcdir}/inkscape-1.0.1-install-layout.patch
}

build() {
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir -p build-${CARCH} && cd build-${CARCH}

  local -a extra_config
  
  if check_option "debug" "y"; then
    extra_config+=(-DCMAKE_BUILD_TYPE=Debug)
  else
    extra_config+=(-DCMAKE_BUILD_TYPE=Release)
  fi

  MSYS=winsymlinks:native \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config[@]} \
    -Wno-dev \
    -DCMAKE_AR=${MINGW_PREFIX}/bin/ar \
    -DWITH_IMAGE_MAGICK=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd ${srcdir}/build-${CARCH}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
}
